package com.ruoyi.borrowing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.borrowing.domain.Borrowing;
import com.ruoyi.borrowing.service.IBorrowingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 借阅管理Controller
 * 
 * @author ynnz
 * @date 2025-05-24
 */
@RestController
@RequestMapping("/borrowing/borrowing")
public class BorrowingController extends BaseController
{
    @Autowired
    private IBorrowingService borrowingService;

    /**
     * 查询借阅管理列表
     */
    @PreAuthorize("@ss.hasPermi('borrowing:borrowing:list')")
    @GetMapping("/list")
    public TableDataInfo list(Borrowing borrowing)
    {
        startPage();
        List<Borrowing> list = borrowingService.selectBorrowingList(borrowing);
        return getDataTable(list);
    }

    /**
     * 导出借阅管理列表
     */
    @PreAuthorize("@ss.hasPermi('borrowing:borrowing:export')")
    @Log(title = "借阅管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Borrowing borrowing)
    {
        List<Borrowing> list = borrowingService.selectBorrowingList(borrowing);
        ExcelUtil<Borrowing> util = new ExcelUtil<Borrowing>(Borrowing.class);
        util.exportExcel(response, list, "借阅管理数据");
    }

    /**
     * 获取借阅管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('borrowing:borrowing:query')")
    @GetMapping(value = "/{borrowId}")
    public AjaxResult getInfo(@PathVariable("borrowId") String borrowId)
    {
        return success(borrowingService.selectBorrowingByBorrowId(borrowId));
    }

    /**
     * 新增借阅管理
     */
    @PreAuthorize("@ss.hasPermi('borrowing:borrowing:add')")
    @Log(title = "借阅管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Borrowing borrowing)
    {
        return toAjax(borrowingService.insertBorrowing(borrowing));
    }

    /**
     * 修改借阅管理
     */
    @PreAuthorize("@ss.hasPermi('borrowing:borrowing:edit')")
    @Log(title = "借阅管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Borrowing borrowing)
    {
        return toAjax(borrowingService.updateBorrowing(borrowing));
    }

    /**
     * 删除借阅管理
     */
    @PreAuthorize("@ss.hasPermi('borrowing:borrowing:remove')")
    @Log(title = "借阅管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{borrowIds}")
    public AjaxResult remove(@PathVariable String[] borrowIds)
    {
        return toAjax(borrowingService.deleteBorrowingByBorrowIds(borrowIds));
    }
}
